//
//  SetGenderView.swift
//  IdleFish
//
//  Created by Ben on 2022/1/2.
//

import SwiftUI

struct SetGenderView: View {
    
    @EnvironmentObject var userDataVM: UserDataViewModel
    
    var body: some View {
        VStack(spacing: 0) {
            
            Spacer()
            
            HStack {
                Button {
                    withAnimation {
                        userDataVM.showGenderPicker.toggle()
                    }
                } label: {
                    Text("取消")
                        .foregroundColor(.black)
                }
                
                Spacer()
                
                Button {
                    Task {
                        await userDataVM.updateUserGender()
                    }
                } label: {
                    Text("确定")
                        .foregroundColor(.black)
                }

            }
            .frame(height: 40)
            .padding(.horizontal, 16)
            .background(
                Color.yellow
            )
            
                .zIndex(1)
            
            Picker("Please choose a color", selection: $userDataVM.selectedGender) {
                ForEach(UserGender.allCases) { gender in
                    Text(gender.value.capitalized)
                        .tag(gender)
                }
            }
            .pickerStyle(.wheel)
            .frame(width: SCREEN_WIDTH, height: 100)
            .padding(.bottom, SCREEN_SAFE_INSETS.bottom)
            .background(Color.white)
            
        }
        .frame(width: SCREEN_WIDTH, height: SCREEN_HEIGHT, alignment: .bottom)
        
        .background(Color.black.opacity(0.4))
    }
}

struct SetGenderView_Previews: PreviewProvider {
    static var previews: some View {
        SetGenderView()
    }
}
